#include "../inc/MD2Model.h"

MD2Model::MD2Model(const char * modelname, const char * skinname) : 
  SolidObject(), m(modelname, skinname)
{
  BoundBox tbb = (*m.getBbox());
  meshDisplacement = tbb.getCenter();
  tbb.max-=meshDisplacement;
  tbb.min-=meshDisplacement;
  bb.addBbox(tbb);
  m.setPos(-meshDisplacement);
  
  m.setAnimation(MD2Mesh::STAND);
}

MD2Model::MD2Model(const char * modelname, const char * skinname, GLfloat s) : 
  SolidObject(), m(modelname, skinname, s)
{
  BoundBox tbb = (*m.getBbox());
  meshDisplacement = tbb.getCenter();
  tbb.max-=meshDisplacement;
  tbb.min-=meshDisplacement;
  bb.addBbox(tbb);
  m.setPos(-meshDisplacement);
  
  m.setAnimation(MD2Mesh::STAND);
}

void MD2Model::draw()
{
  glPushMatrix();
    renderTranslation();
    renderRotation();
    
    m.draw();
    if (drawBoundBox()) bb.draw();
    
  glPopMatrix();
}

void MD2Model::update(double dt)
{
  CoordF c(0,0,1);
  c.rotateInY(getRotation().y);
  setDir(c);
  m.update(dt);
}
